#include <iostream>
#include <queue>
#include <map>
using namespace std;
//int a[400005]={0};



int main(){
	int n,k,ans=0;
	bool can_break=false;
	cin>>n>>k;
	if(n > k){
		ans = n-k;
		can_break = true;
	}
	queue<int> q;
	q.push(n);
	map<int,int> m;
//	a[n] = 1;
	while(!can_break){
		int size = q.size();
		for(int i=0;i<size;i++){
			int l=q.front();
			q.pop();
			if(l-1 == k  ||  l+1 == k  ||  l*2 == k){
				can_break = true;
				break;
			}
			if(l-1 >= 0  &&  m[l-1] == 0){
				q.push(l-1);
				m[l-1] = 1;
			}
			if(m[l+1] == 0){
				q.push(l+1);
				m[l+1] = 1;
			}
			if(l*2 > 0  &&  l <= 200000  &&  m[l*2] == 0){
				q.push(l*2);
				m[l*2] = 1;
			}
		}
		ans++;
	}
	cout<<ans;
}
